import pymysql
from app import app

# 获取数据库配置
with app.app_context():
    db_uri = app.config['SQLALCHEMY_DATABASE_URI']
    
# 解析数据库连接信息
# 示例: mysql+pymysql://root:123456@localhost:33061/autotest
import re
match = re.match(r'mysql\+pymysql://(.*?):(.*?)@(.*?)(?::(\d+))?/(.*?)$', db_uri)
if match:
    user, password, host, port, database = match.groups()
    if port is None:
        port = 3306
    else:
        port = int(port)
    
    # 连接数据库
    connection = pymysql.connect(
        host=host,
        port=port,
        user=user,
        password=password,
        database=database
    )
    
    try:
        with connection.cursor() as cursor:
            # 查询test_cases表结构
            cursor.execute("DESCRIBE test_cases")
            columns = cursor.fetchall()
            
            print("test_cases表结构:")
            for column in columns:
                print(f"  {column[0]}: {column[1]} {column[2]} {column[3]} {column[4]} {column[5]}")
                
    finally:
        connection.close()
else:
    print("无法解析数据库连接信息")
    print(f"数据库URI: {db_uri}")